package com.base.cn.platform.os.controller.course.cou;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.constants.CommonConstants;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.common.utils.FileExportImportUtil;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.course.CourseType;
import com.base.cn.platform.os.common.utils.file.FileDownloadUtil;
import com.base.cn.platform.os.common.utils.qrCode.QrCodeUtil;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.service.course.catalog.CourseCatalogService;
import com.base.cn.platform.os.service.course.cou.CourseService;
import com.base.cn.platform.os.service.course.cou.packageCou.PackageCourseService;
import com.base.cn.platform.os.service.course.cou.record.CoursePlayRecordService;
import com.base.cn.platform.os.service.course.material.CouMaterialService;
import com.base.cn.platform.os.service.manage.teacher.SysTeacherService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;

/**
 * 后台课程管理
 *
 * @author s.li
 * @create 2018-04-17-13:34
 */
@Controller
@RequestMapping("/admin/course/cou/")
public class AdminCourseController extends AdminBaseController{
    @Autowired
    private CourseService courseService;
    @Autowired
    PackageCourseService packageCourseService;
    @Autowired
    CourseCatalogService courseCatalogService;
    @Autowired
    SysTeacherService  sysTeacherService;
    @Autowired
    private CoursePlayRecordService coursePlayRecordService;
    @Autowired
    private CouMaterialService couMaterialService;
    @Autowired
    private CommonConstants commonConstants;



    /**
     * 复制课程
     * @param courseId 课程ID
     * @return Map<String,Object>
     */
    @RequestMapping("/copyCourse")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.COURSE,action = "复制课程数据")
    public Map<String,Object> copyCourse(HttpServletRequest request,
                                         @RequestParam("courseId") BigDecimal courseId){
        BigDecimal sysUserId = loginUtil.getLoginUserId(request);
        return courseService.copyCourse(courseId,sysUserId);
    }

    /**
     * 初始化课程列表
     * @return 列表页面
     */
    @RequestMapping("/courseList")
    public String courseList(Model model){
        model.addAttribute("courseTypeList",CourseType.values());
        return resultPage("/course/cou/course_list");
    }

    /**
     * 获取课程数据
     * @param params
     * @param currentPage 当前页码
     * @return 列表页面
     */
    @RequestMapping("/ajaxCourseList")
    public String ajaxCourseList(Model model,
                                 @RequestBody Map<String,Object> params,
                                 @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){
        params.put("notCourseTypeKeys","'PACKAGE','LIVE','SMALL'");
        params.put("type",1);
        Map<String,Object> dataMap = courseService.findWebCoursePage(params,currentPage,12,false,true,true,true,false);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/course/cou/ajax_course_list");
    }

    /**
     * 获取课程统计数据
     * @return 页面
     */
    @RequestMapping("/ajaxCountNum")
    public String ajaxCountNum(Model model,@RequestBody Map<String,Object> params,@RequestParam("courseType") String courseType){
        if(courseType.equals(CourseType.COURSE_TYPE_PACKAGE.getKey())){
            params.put("courseTypeKey",CourseType.COURSE_TYPE_PACKAGE.getKey());
        }else if(courseType.equals(CourseType.COURSE_TYPE_LIVE.getKey())){
            params.put("courseTypeKey",CourseType.COURSE_TYPE_LIVE.getKey());
        }else if(courseType.equals(CourseType.COURSE_TYPE_SMALL.getKey())){
            params.put("courseTypeKey",CourseType.COURSE_TYPE_SMALL.getKey());
        }else{
            params.put("notCourseTypeKeys","'"+CourseType.COURSE_TYPE_PACKAGE.getKey()+"','"+CourseType.COURSE_TYPE_LIVE.getKey()+"','"+CourseType.COURSE_TYPE_SMALL.getKey()+"'");
        }
        BigDecimal courseCount = courseService.courseCount(params);
        params.put("status",1);
        BigDecimal onCount = courseService.courseCount(params);
        params.put("status",2);
        BigDecimal downCount = courseService.courseCount(params);
        params.put("status",0);
        BigDecimal notCount = courseService.courseCount(params);
        model.addAttribute("courseCount",courseCount);
        model.addAttribute("onCount",onCount);
        model.addAttribute("downCount",downCount);
        model.addAttribute("notCount",notCount);
        model.addAttribute("courseTypeKey",courseType);
        return resultPage("/course/cou/ajax_count_list");
    }

    /**
     * 初始化课程类型页面
     * @return 操作页面
     */
    @RequestMapping("/initCourseTypeIndex")
    public String initCourseTypeIndex(){
        return resultPage("/course/cou/course_index");
    }

    /**
     * 初始化修改/添加课程/套餐页面
     * @param id 课程/套餐ID
     * @return 操作页面
     */
    @RequestMapping(value = {"/initUpdate","/initAdd",
            "/initLiveUpdate","/initLiveAdd",
            "/initUpdatePackage","/initAddPackage",
            "/initSmallUpdate","/initSmallAdd"})
    public String initUpdateOrAdd(Model model,
                                  @RequestParam(value = "id",required = false,defaultValue = "0") BigDecimal id,
                                  @RequestParam(value = "courseType",required = false) String courseType){
        Map<String,Object> course =null;
        if(DataUtil.idIsNotNull(id)){
            course = courseService.findCourseById(id,true,false,false, false);
        }
        if(ObjectUtils.isEmpty(course)){
            course = new HashMap<>();
            course.put("id",id);
            course.put("status",0);
            course.put("createClass",0);
            course.put("allow",0);
            course.put("courseTypeKey",courseType);
        }
        model.addAttribute("nowYear",Calendar.getInstance().get(Calendar.YEAR));
        model.addAttribute("maxYear",Calendar.getInstance().get(Calendar.YEAR)+2);
        model.addAttribute("course",course);
        return resultPage("/course/cou/save_course");
    }

    /**
     * 保存课程数据
     * @param course 课程数据对象
     * @return Map<String,Object>
     */
    @RequestMapping("/saveCourse")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.COURSE,action = "保存课程数据")
    public Map<String,Object> saveCourse(HttpServletRequest request,
                                         @RequestBody Map<String, Object> course){
        BigDecimal userId = loginUtil.getLoginUserId(request);
        course.put("createUserId",userId);
        return courseService.saveCourse(course);
    }

    /**
     * 初始化课程/套餐详情基本信息页面
     * @param model
     * @param courseId 课程/套餐ID
     * @return 操作页面
     */
    @RequestMapping(value = {"/initUpdateCourseInfo","/initUpdateLiveInfo","/initUpdatePackageInfo"})
    public String initUpdateCourseInfo(Model model,
                                       @RequestParam("courseId") BigDecimal courseId){
        Map<String,Object> course = courseService.findCourseById(courseId,false,false,false, false);
        model.addAttribute("course",course);
        return resultPage("/course/cou/save_course_info");
    }

    /**
     * 保存课程描述信息
     * @param course 课程对象
     * @return Map<String,Object>
     */
    @RequestMapping("/saveCourseInfo")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.COURSE,action = "保存或修改课程描述信息")
    public Map<String,Object> saveCourseInfo(@RequestBody Map<String,Object> course){
        return courseService.saveCourseInfo(course);
    }

    /**
     * 更新课程的学习顺序
     * @param courseId 课程ID
     * @param studyLimit 学员顺序
     * @param scorePercent 得分率
     * @return Map<String,Object>
     */
    @RequestMapping("/updateCourseStudyLimit")
    @ResponseBody
    public Map<String,Object> updateCourseStudyLimit(@RequestParam("courseId") BigDecimal courseId,
                                                     @RequestParam("studyLimit") int studyLimit,
                                                     @RequestParam("scorePercent") double scorePercent){
        Map<String,Object> course = new HashMap<>();
        course.put("id",courseId);
        course.put("studyLimit",studyLimit);
        course.put("scorePercent",scorePercent);
        return courseService.updateCourseStudyLimit(course);
    }

    /**
     * 修改完结状态
     * @param courseIds 课程ID串，多个ID以“,”隔开
     * @return  Map<String,Object>
     */
    @RequestMapping("/updateContextStatus")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.COURSE,action = "修改课程完结状态")
    public Map<String,Object> updateContextStatus(@RequestParam("courseIds") String courseIds){
        return courseService.updateContextStatus(courseIds);
    }

    /**
     * 修改课程状态
     * @param courseIds 课程ID串，多个ID以“,”隔开
     * @param status 状态，1下架，2下架，3删除
     * @return Map<String,Object>
     */
    @RequestMapping("/updateCourseStatus")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.COURSE,action = "修改课程状态")
    public Map<String,Object> updateCourseStatus(@RequestParam("courseIds") String courseIds,@RequestParam("status") int status){
        return courseService.updateCourseStatus(courseIds,status);
    }

    /**
     * 初始化选择课程列表
     * @param type  1是不排除是否选过的  2 是排除
     * @param subjectIds 课程专业查询条件
     * @return 列表页面
     */
    @RequestMapping("/selectCourseList")
    public String selectCourseList(Model model,
                                   @RequestParam(value = "packageId",required = false,defaultValue = "0") BigDecimal packageId,
                                   @RequestParam(value = "classId",required = false,defaultValue = "0") BigDecimal classId,
                                   @RequestParam(value = "selectType",required = false,defaultValue = "radio") String selectType,
                                   @RequestParam(value = "type",required = false,defaultValue = "1") int type,
                                   @RequestParam(value = "subjectIds", required = false, defaultValue = "") String subjectIds,
                                   @RequestParam(value = "courseTypeKey", required = false, defaultValue = "") String courseTypeKey){
        model.addAttribute("type",type);
        model.addAttribute("selectType",selectType);
        model.addAttribute("packageId",packageId);
        model.addAttribute("classId",classId);
        model.addAttribute("subjectIds", subjectIds);
        model.addAttribute("courseTypeKey", courseTypeKey);
        model.addAttribute("courseTypeList", CourseType.values());
        return resultPage("/course/cou/select_course_list");
    }

    /**
     * 获取选择课程数据
     * @param params
     * @param currentPage 当前页码
     * @return 列表页面
     */
    @RequestMapping("/ajaxSelectCourseList")
    public String ajaxSelectCourseList(Model model,
                                       @RequestBody Map<String,Object> params,
                                       @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){
        params.put("status",1);//只查询状态正常的
        params.put("notExpire",true);//只查询未过期的课程
        Map<String,Object> dataMap = courseService.findCoursePage(params,currentPage,10,false,true,true);
        model.addAttribute("dataMap",dataMap);
        model.addAttribute("selectType",params.get("selectType"));
        model.addAttribute("courseTypeList", CourseType.values());
        return resultPage("/course/cou/ajax_select_course_list");
    }

    /**
     * 查看课程详情
     * @param model
     * @param courseId 课程id
     * @return
     */
    @RequestMapping("/previewCourse")
    public String previewCourse(Model model,
                                @RequestParam("courseId") String courseId,
                                @RequestParam("courseType") String courseType){
        BigDecimal id = new BigDecimal(courseId);
        Map<String,Object> course = courseService.findCourseById(id,true,true,false,true);
        List<Map<String,Object>> packageList = null;
        if(StringUtils.isNotEmpty(courseType) && courseType.equals(CourseType.COURSE_TYPE_PACKAGE.getKey())){
            packageList = packageCourseService.findPackageCourseByPackageId(id,true);
        }
        List<Map<String,Object>> liveMap = null;
        if(StringUtils.isNotEmpty(courseType) && courseType.equals(CourseType.COURSE_TYPE_LIVE.getKey())){
            //获取课程直播素材
            liveMap =  courseCatalogService.findCourseCatalogByCourseId(id,true,false,false,false);
        }
        model.addAttribute("course",course);
        model.addAttribute("packList",packageList);
        model.addAttribute("liveMap",liveMap);
        return resultPage("/user/user/preview_course");
    }




    /**
     * 课程随堂练习
     * @return 列表页面
     */
    @RequestMapping("/coursePracticeList")
    public String coursePracticeList(Model model,@RequestParam(value = "courseId",required = false) BigDecimal  courseId){
        model.addAttribute("courseId",courseId);
        return resultPage("/course/cou/practice/course_practice_list");
    }

    /**
     * 获取课程随堂练习数据
     * @param params
     * @param currentPage 当前页码
     * @return 列表页面
     */
    @RequestMapping("/ajaxCoursePracticeList")
    public String ajaxCoursePracticeList(Model model,
                                 @RequestBody Map<String,Object> params,
                                 @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){
        params.put("notCourseTypeKeys","'PACKAGE','LIVE'");
        params.put("type",1);//只查询状态正常的
        params.put("noNodeNum",1);//只查询状态正常的
        Map<String,Object> dataMap = courseService.findCoursePracticePage(params,currentPage,10);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/course/cou/practice/ajax_course_practice_list");
    }

    /**
     * 课程随堂练习
     * @return 列表页面
     */
    @RequestMapping("/coursePracticeInfo")
    public String coursePracticeInfo(){
        return resultPage("/course/cou/practice/course_practice_info");
    }




    @RequestMapping("/createForm")
    public String createForm(){
        return resultPage("/course/cou/from/create_form");
    }




    /**
     * 获取课程随堂练习数据
     * @return 列表页面
     */
    @RequestMapping("/getTeacherName")
    @ResponseBody
    public Map getTeacherName(@RequestParam("courseId") BigDecimal courseId ) {
        Map<String, Object> courseById = courseService.findCourseById(courseId, true, false, false, false);
        return ResultUtil.SUCCESS(courseById.get("teacherList"));
    }


    /**
     * 获取选择课程数据
     * @param params
     * @param currentPage 当前页码
     * @return 列表页面
     */
    @RequestMapping("/ajaxSelectIntegralCourseList")
    public String ajaxSelectIntegralCourseList(Model model,
                                       @RequestBody Map<String,Object> params,
                                       @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){
        //只查询状态正常的
        params.put("status",1);
        //只查询未过期的课程
        params.put("notExpire",true);
        params.put("type",1);
        model.addAttribute("courseTypeList", CourseType.values());

        Map<String,Object> dataMap = courseService.findCoursePage(params,currentPage,10,false,true,true);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/course/cou/ajax_select_course_list");
    }

    /**
     * 计算课程合计时间
     *
     * @return Course
     */
    @RequestMapping("/durationSum")
    @ResponseBody
    public Map<String, Object> durationSum(@RequestParam("courseId") BigDecimal courseId) {
        Map<String,Object> res = courseService.durationSum(courseId);
        return res;
    }

    /**
     * 查看课程教学数据
     *
     * @return 操作页面
     */
    @RequestMapping(value = {"showCouTeachingData","liveData","courseData","smallData","packageData"})
    public String showCouTeachingData(Model model, @RequestParam("id") BigDecimal id) {
        model.addAttribute("courseInfo", courseService.findCourseById(id, false, false, true, true));
        return resultPage("/course/cou/courseTeachData/course_teaching_data");
    }

    /**
     * 课程的总购买人数，学习人数，课程完成人数，完成率
     * @param courseId
     * @return
     */
    @RequestMapping("/findCourseStatis")
    @ResponseBody
    public Map<String, Object> findCourseStatis(@RequestParam("courseId")BigDecimal courseId) {
        return ResultUtil.SUCCESS(coursePlayRecordService.findCourseStatis(courseId));
    }

    /**
     * 课程分享二维码弹窗
     *
     * @param model
     * @param courseId
     * @return
     */
    @RequestMapping("/shareCourseToUser")
    public String shareCourseToUser(Model model, @RequestParam("courseId") BigDecimal courseId, @RequestParam("type") String type) {
        String temp = null;
        if (CourseType.COURSE_TYPE_LIVE.getKey().equals(type)) {
            temp = "liveInfo";
        } else if (CourseType.COURSE_TYPE_SMALL.getKey().equals(type)) {
            temp = "smallClassInfo";
        }else{
            temp = "info";
        }
        model.addAttribute("type", temp);
        model.addAttribute("courseId", courseId);
        return resultPage("/course/cou/share-course-alert");
    }
    /**
     * 下载分享课程的二维码
     * @param request
     * @param shareUrl
     * @return
     */
    @RequestMapping("/encodeQRCode")
    public void encodeQRCode(HttpServletRequest request,
                             HttpServletResponse response,
                             @RequestParam("shareUrl") String shareUrl){
        try {
            //二维码生成后的下载地址
            QrCodeUtil qrCodeUtil = new QrCodeUtil();
            StringBuilder adminPath = new StringBuilder(commonConstants.get(CommonConstants.ADMIN_PATH));
            //二维码名称中文
            String qrCodeCourse = "课程分享二维码.png";
            final String userAgent = request.getHeader("USER-AGENT");
            //IE浏览器
            if (org.thymeleaf.util.StringUtils.contains(userAgent, "MSIE")) {
                qrCodeCourse = URLEncoder.encode(qrCodeCourse, "UTF-8");
                //google,火狐浏览器
            } else if (org.thymeleaf.util.StringUtils.contains(userAgent, "Mozilla")) {
                qrCodeCourse = new String(qrCodeCourse.getBytes(), "ISO8859-1");
            } else {
                //其他浏览器
                qrCodeCourse = URLEncoder.encode(qrCodeCourse, "UTF-8");
            }
            qrCodeUtil.QrExamPaperCode(shareUrl,qrCodeCourse,response);
        }catch (IOException e) {
            System.out.println("【BillCommonFileServiceImpl】 download ==IOException "+e.getMessage());
            e.printStackTrace();
        }
    }

    /**
     * 导出直播间信息
     *
     * @return
     */
    @RequestMapping("/downloadChatMsgList")
    public ResponseEntity<byte[]> downloadChatMsgList(@RequestParam("materialId") BigDecimal materialId) throws Exception {
        Map<String,Object> materialMap = couMaterialService.findMaterialById(materialId,false,false);
        String type = materialMap.get("playType").toString();
        PageInfo<Map<String, Object>> pageInfo = coursePlayRecordService.getChatMsgPage( materialId, 1000, 1);
        List<Map<String, Object>> chatMsgList = pageInfo.getList();
        String[] heads = new String[]{"ID", "昵称", "角色", "时间", "内容"};
        //生成文件的容器
        List<Map<String, Object>> srcFile = new ArrayList<>();
        //文件名
        String expName = "聊天信息数据" + System.currentTimeMillis();
        //获取数据
        Map<String, String> roleType = new HashMap<>();
//        0:未统计，1:主讲，2:助教，3:主持人，4:学员
        if("CC".equals(type)){
            roleType.put("1.0", "主讲");
            roleType.put("2.0", "助教");
            roleType.put("3.0", "主持人");
            roleType.put("4.0", "学员");
        }else{
            roleType.put("1", "老师");
            roleType.put("2", "助教");
            roleType.put("3", "学生");
        }
        if (ObjectUtils.isNotEmpty(chatMsgList)) {
            List<List<String>> data = new ArrayList<>();
            chatMsgList.stream().forEach(e -> {
                if ("CC".equals(type)) {
                    data.add(Arrays.asList(
                            e.get("viewerId").toString(),
                            e.get("viewerName").toString(),
                            roleType.get(e.get("viewerRole").toString()),
                            e.get("time").toString(),
                            e.get("content").toString()
                    ));
                } else {
                    data.add(Arrays.asList(
                            e.get("uuid").toString(),
                            e.get("nickName").toString(),
                            roleType.get(e.get("role").toString()),
                            e.get("logTime").toString(),
                            e.get("content").toString()
                    ));
                }
            });
            //每2000数据一个execl，如果页数大于1循环生成
            //OrderExportExcelUtils.generateFile(data, heads, expName + "_" + i + ".xls", srcFile);
            Map<String,Object> files = new HashMap<>();
            InputStream inputStream = FileExportImportUtil.createExcel(heads, data);
            files.put("name",expName+".xls");
            files.put("inputStream",inputStream);
            srcFile.add(files);
        }
        return FileDownloadUtil.createRar(srcFile, expName);
    }


    /**
     * 导出直播互动信息
     *
     * @return
     */
    @RequestMapping("/downloadInteractiveList")
    public ResponseEntity<byte[]> downloadInteractiveList(@RequestParam("materialId") BigDecimal materialId) throws Exception {
        Map<String,Object> materialMap = couMaterialService.findMaterialById(materialId,false,false);
        String type = materialMap.get("playType").toString();
        PageInfo<Map<String, Object>> pageInfo = coursePlayRecordService.getInteractivePage( materialId, 1000, 1);
        List<Map<String, Object>> interactiveList = pageInfo.getList();
        String[] heads = new String[]{"ID", "昵称", "观看时长", "进出次数", "聊天次数","提问次数","签到次数","答卷次数\n"};
        //生成文件的容器
        List<Map<String, Object>> srcFile = new ArrayList<>();
        //文件名
        String expName = "直播互动消息" + System.currentTimeMillis();
        //获取数据
//        0:未统计，1:主讲，2:助教，3:主持人，4:学员
        if (ObjectUtils.isNotEmpty(interactiveList)) {
            List<List<String>> data = new ArrayList<>();
            interactiveList.stream().forEach(e->{
                if("CC".equals(type)){
                    data.add(Arrays.asList(
                            e.get("viewerId").toString(),
                            e.get("viewerName").toString(),
                            e.get("watchTime").toString(),
                            e.get("enterLeaveCount").toString(),
                            e.get("chatCount").toString(),
                            e.get("questionCount").toString(),
                            e.get("rollcallCount").toString(),
                            e.get("questionnaireCount").toString()
                    ));
                }else{
                    data.add(Arrays.asList(
                            e.get("uuid").toString(),
                            e.get("nickName").toString(),
                            e.get("onlineTime").toString(),
                            e.get("enterNum").toString(),
                            e.get("chatMsgNum").toString(),
                            e.get("handsUpNum").toString(),
                            e.get("signInNum").toString(),
                            e.get("selectorNum").toString()
                    ));
                }

            });

            //每2000数据一个execl，如果页数大于1循环生成
//            OrderExportExcelUtils.generateFile(data, heads, expName + "_" + i + ".xls", srcFile);

            Map<String,Object> files = new HashMap<>();
            InputStream inputStream = FileExportImportUtil.createExcel(heads, data);
            files.put("name",expName+".xls");
            files.put("inputStream",inputStream);
            srcFile.add(files);
        }
        return FileDownloadUtil.createRar(srcFile, expName);
    }


    /**
     * 导出学员签到记录
     *
     * @return
     */
    @RequestMapping("/downloadRollCallList")
    public ResponseEntity<byte[]> downloadRollCallList(@RequestParam("materialId") BigDecimal materialId) throws Exception {
        Map<String,Object> materialMap = couMaterialService.findMaterialById(materialId,false,false);
        String type = materialMap.get("playType").toString();
        PageInfo<Map<String, Object>> pageInfo = coursePlayRecordService.getRollCallPage( materialId, 100, 1);
        List<Map<String, Object>> rollcallList = pageInfo.getList();
        String[] heads = new String[]{"ID", "昵称", "状态"};
        //生成文件的容器
        List<Map<String, Object>> srcFile = new ArrayList<>();
        //文件名
        String expName = "学员签到记录" + System.currentTimeMillis();
        //获取数据
        if (ObjectUtils.isNotEmpty(rollcallList)) {
            Map<String, String> roleType = new HashMap<>();
            roleType.put("1.0", "已签到");
            roleType.put("0.0", "未签到");
            List<List<String>> data = new ArrayList<>();
            rollcallList.stream().forEach(e -> {
                if ("CC".equals(type)) {
                    data.add(Arrays.asList(
                            e.get("viewerId").toString(),
                            e.get("viewerName").toString(),
                            roleType.get(e.get("checked").toString())
                    ));
                } else {
                    data.add(Arrays.asList(
                            e.get("uuid").toString(),
                            e.get("nickName").toString(),
                            e.get("signInNum").toString().equals("0") ? "未签到" : "已签到"
                    ));
                }
            });

            //每2000数据一个execl，如果页数大于1循环生成
//            OrderExportExcelUtils.generateFile(data, heads, expName + "_" + i + ".xls", srcFile);

            Map<String,Object> files = new HashMap<>();
            InputStream inputStream = FileExportImportUtil.createExcel(heads, data);
            files.put("name",expName+".xls");
            files.put("inputStream",inputStream);
            srcFile.add(files);
        }
        return FileDownloadUtil.createRar(srcFile, expName);
    }

    /**
     * 修改课程分销推广状态
     * @param courseId 课程id
     * @param allow  状态 1 不可分销  2  开启分销
     * @return
     */
    @RequestMapping("/updateCourseAllow")
    @ResponseBody
    Map<String, Object> updateCourseAllow(@RequestParam("courseId")BigDecimal courseId,@RequestParam("allow")Integer allow){
        return courseService.updateCourseAllow(courseId, allow);
    }
}
